package miage.gestioncabinet.coredb;

import java.util.Calendar;

import javax.persistence.*;

import miage.gestioncabinet.api.Patient;

@Entity
@Table (name="patient")
@NamedQueries({
	@NamedQuery(name="rechercherPatients", query="SELECT p FROM PatientDB p WHERE p.personne.nom LIKE :keyword OR p.personne.prenom LIKE :keyword")
})
public class PatientDB extends PersonneDB implements Patient {

	@Column
	private String sexe;
	@Column
	private Calendar dateNaissance;
	@OneToOne
	private PersonneDB personne;
	
	private static final long serialVersionUID = 2684950790652751108L;

	public String getSexe() {
		return this.sexe;
	}
	
	public String setSexe(String sexe) {
		return this.sexe=sexe;
	}

	@Override
	public Calendar getDateNaissance() {	
		return this.dateNaissance;
	}

	@Override
	public void setDateNaissance(Calendar dateNaissance) {	
		this.dateNaissance = dateNaissance;
	}

	@Override
	public Integer getAge() {
		Calendar today = Calendar.getInstance();
		return today.get(Calendar.YEAR) - this.dateNaissance.get(Calendar.YEAR); 
	}


}
